package J4_27;

import java.util.Scanner;

public class test {
    public static int bestTime (int[] prices) {
        int n = prices.length;
        int[][] dp = new int[n][2];
        dp[0][0] = -prices[0];
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i-1][0],dp[i-1][1]-prices[i]);
            dp[i][1] = Math.max(dp[i-1][0]+prices[i],dp[i-1][1]);
        }
        return dp[n-1][1];
    }

    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5};
        bestTime(arr);
    }

    public void reverseStr(String str) {
        String[] strArr = str.split(" ");
        StringBuilder ret = new StringBuilder();
        for (int i = 0; i < strArr.length; i++) {
            StringBuilder tmp = new StringBuilder(strArr[i]).reverse();
            ret.append(tmp);
        }
        System.out.println(ret.reverse());
    }
    public static void app() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt(), a = in.nextInt(), b = in.nextInt();
        if (n == 1 && m == 1) {
            System.out.println(0);
            return;
        }
        int ret = 0;
        if (a > b) {
            ret = getRet(n, m, a, b, ret);
        } else {
            ret = getRet(m, n, b, a, ret);
        }
        System.out.println(ret);
    }

    private static int getRet(int n, int m, int a, int b, int ret) {
        while (n > 1 && m > 0) {
            ret += a;
            n -= 2;
            m--;
        }
        while (m > 1 && n > 0) {
            ret += b;
            m -= 2;
            n--;
        }
        return ret;
    }
}
